<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>

							<li style="white-space: nowrap; width: 120px">
								<label>测试计划:</label>
								<select id="relPlanId" name="relPlanId">
									<option value="">所有计划</option>
									<option th:each="item:${plans}" th:text="${item.name}" th:value="${item.id}" ></option>

								</select>
							</li>

							<li style="padding-left: 50px">
								<label>测试用例:</label>
								<input type="text" name="relCaseId"/>
							</li>


							<li>
								执行状态： <select id="status" name="status">
									<option value="">全部</option>
									<option value="0">未开始</option>
									<option value="1">执行中</option>
									<option value="2">执行成功</option>
									<option value="3">执行失败</option>
								</select>
							</li>

							<li>
								开始时间：<input type="text" name="startTime"/>
							</li>

							<li>
								结束时间：<input type="text" name="endTime"/>
							</li>

							<li>
								备注：<input type="text" name="remark"/>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="jmeter:jmeterTestPlanRecord:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
	 <script th:src="@{/ajax/libs/select/select2.js}"></script>
	 <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('jmeter:jmeterTestPlanRecord:edit')}]];
        var removeFlag = [[${@permission.hasPermi('jmeter:jmeterTestPlanRecord:remove')}]];
        var prefix = ctx + "jmeter/jmeterTestPlanRecord";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				sortOrder: 'desc',
				sortName: 'createTime',
                modalName: "jmx测试计划执行记录",
				search: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : 'id',
					visible: false
				},
				{
					field : 'relPlanName',
					title : '计划名称',
					sortable: true
				},
				{
					field : 'relCaseName', 
					title : '用例名称',
					sortable: true
				},

				{
					field : 'status',
					title : '执行状态',
					sortable: true,
					formatter: function (value,
										 row, index) {
						if (value == 0) {
							var hdiv = '<span id="statusSpan' + row.id + '" class="glyphicon " style="color: rgba(175,155,173,0.51);"> 未开始</span>';
						} else if (value == 1) {
							var hdiv = '<span id="statusSpan' + row.id + '" class="glyphicon " style="color: rgb(199,198,45);"> 执行中</span>';
						} else if (value == 2) {
							var hdiv = '<span id="statusSpan' + row.id + '" class="glyphicon " style="color: rgba(66,220,21,0.96);"> 执行成功</span>';
						} else if (value == 3) {
							var hdiv = '<span id="statusSpan' + row.id + '" class="glyphicon " style="color: rgb(255,39,61); font-size: 14px;"> 执行失败</span>';
						}
						return '<font id="statusFont' + row.id + '">' + hdiv + '</font>';
					}
				},
				{
					field : 'errorMsg',
					title : '错误信息',
					sortable: true
				},
				{
					field : 'duration',
					title : '耗时',
					size: 10,
					sortable: true
				},
				{
					field : 'startTime',
					title : '开始时间',
					sortable: true,
					formatter: function (value,
										 row, index) {
						return $.common.formatTime(value);
					}
				},
				{
					field : 'endTime', 
					title : '结束时间',
					sortable: true,
					formatter: function (value,
										 row, index) {
						if(row.status==2 || row.status==3){
							return $.common.formatTime(value);
						}else {
							return '';
						}

					}
				},
				{
					field : 'createTime', 
					title : '创建时间',
					sortable: true,
					formatter: function (value,
										 row, index) {
						return $.common.formatTime(value);
					}
				},
				{
					field : 'remark', 
					title : '备注',
					sortable: true
				},
		        {
		            title: '操作',
		            align: 'center',
					events: window.operateEvents,
					formatter: function(value, row, index) {
						var actions = [];
						if(row.status==2){
							actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="seeGraphReport(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看报表</a> ');
						}
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
					}
		        }]
            };
            $.table.init(options);

			$("#relPlanId").select2();
			var relPlanId = [[${relPlanId}]];
			$("#relPlanId").val(relPlanId).change();
			$.table.search();

		});



		function seeGraphReport(id) {
			createMenuItem('/jmeter/report/view/jmeter_report/index?recordId='+id,'查看报表');
		}
    </script>
</body>
</html>